#pragma once

#include "CallAction.h"

#include "OutputPin.h"
#include "Parameter.h"

namespace uml {

const bool CallAction::isSynchronous_default_ = true;
CallAction::CallAction(const QString& umlType)
    : InvocationAction(umlType) {}

void CallAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    InvocationAction::fromJson(json, errorList);
    isSynchronous_ = json.value("isSynchronous").toBool(isSynchronous_default_);
    JsonSerializable::fromJsonArray(results_, "results", json, errorList);
}

void CallAction::toJson(QJsonObject& json) {
    InvocationAction::toJson(json);
    if (isSynchronous_ != isSynchronous_default_) {
        json.insert("isSynchronous", isSynchronous_);
    }
    JsonSerializable::toJsonArray(results_, "results", json);
}

/// <summary>
/// isSynchronous getter
/// If true, the call is synchronous and the caller waits for completion of the
/// invoked Behavior. If false, the call is asynchronous and the caller proceeds
/// immediately and cannot receive return values.
/// </summary>
bool CallAction::isSynchronous() const {
    return isSynchronous_;
}

/// <summary>
/// isSynchronous setter
/// If true, the call is synchronous and the caller waits for completion of the
/// invoked Behavior. If false, the call is asynchronous and the caller proceeds
/// immediately and cannot receive return values.
/// </summary>
void CallAction::setIsSynchronous(bool value) {
    isSynchronous_ = value;
}

/// <summary>
/// results getter
/// The OutputPins on which the reply values from the invocation are placed (if the
/// call is synchronous).
/// </summary>
vector<shared_ptr<OutputPin>>& CallAction::results() {
    return results_;
}

} // namespace uml
